package com.jlwl.houseservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jlwl.houseservice.common.Result;
import com.jlwl.houseservice.entity.Employee;
import com.jlwl.houseservice.service.EmployeeService;
import com.jlwl.houseservice.vo.EmployeeDetailVO;
import com.jlwl.houseservice.vo.EmployeeQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工控制器
 */
@RestController
@RequestMapping("/employees")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 获取员工列表
     */
    @GetMapping
    public Result<Page<Employee>> list(EmployeeQueryVO queryVO) {
        Page<Employee> page = employeeService.pageList(queryVO);
        return Result.success(page);
    }

    /**
     * 获取员工详情
     */
    @GetMapping("/{id}")
    public Result<EmployeeDetailVO> getDetail(@PathVariable Integer id) {
        EmployeeDetailVO detailVO = employeeService.getEmployeeDetail(id);
        if (detailVO == null) {
            return Result.error("员工不存在");
        }
        return Result.success(detailVO);
    }

    /**
     * 根据工作类型获取员工列表
     */
    @GetMapping("/job-type/{jobType}")
    public Result<List<Employee>> getEmployeesByJobType(@PathVariable String jobType) {
        List<Employee> list = employeeService.getEmployeesByJobType(jobType);
        return Result.success(list);
    }

    /**
     * 获取推荐员工列表
     */
    @GetMapping("/recommend")
    public Result<List<Employee>> getRecommendEmployees(@RequestParam(defaultValue = "6") Integer limit) {
        List<Employee> list = employeeService.getRecommendEmployees(limit);
        return Result.success(list);
    }
} 